//
//  SLSocialSecurityCardTableViewCell.m
//  SulitLoanDemo
//
//  Created by 虞嘉伟 on 2025/2/22.
//

#import "SLSocialSecurityCardTableViewCell.h"
#import <YYKit.h>
#import <Masonry.h>
#import "SLCircleTitleComponent.h"



@implementation SLSocialSecurityCard

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.titleView];
        [self addSubview:self.imageView];
        [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self);
            make.top.equalTo(self);
            make.height.mas_equalTo(54);
        }];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self);
            make.top.equalTo(self.titleView.mas_bottom);
            make.bottom.equalTo(self);
        }];
        
        [self addSubview:self.completeView];
        [self.completeView addSubview:self.aligment];
        [self.completeView addSubview:self.completeIcon];
        [self.completeView addSubview:self.completeTitleLabel];
        
        [self addSubview:self.mymaskView];
        [self.completeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.imageView);
            make.height.mas_equalTo(59);
        }];
        [self.aligment mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.completeView);
        }];
        [self.completeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.aligment);
            make.centerY.equalTo(self.aligment);
            make.width.height.mas_equalTo(31);
        }];
        [self.completeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.completeIcon.mas_right).offset(10);
            make.right.equalTo(self.aligment);
            make.top.bottom.equalTo(self.aligment);
        }];
        
        [self.mymaskView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.imageView);
        }];
    }
    return self;
}

- (void)setIsComplete:(BOOL)isComplete {
    _isComplete = isComplete;
    if (isComplete) {
        self.completeView.hidden = NO;
        self.mymaskView.hidden = NO;
    } else {
        self.completeView.hidden = YES;
        self.mymaskView.hidden = YES;
    }
}

- (SLCircleTitleComponent *)titleView {
    if (!_titleView) {
        _titleView = [SLCircleTitleComponent new];
        _titleView.titleLabel.text = @"Id Card Portrait Face Photo";
    }
    return _titleView;
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [UIImageView new];
        _imageView.backgroundColor = UIColor.whiteColor;
        _imageView.layer.cornerRadius = 20;
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _imageView;
}

- (UIView *)completeView {
    if (!_completeView) {
        _completeView = [UIView new];
        _completeView.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _completeView.layer.borderWidth = 1.5;
        _completeView.layer.cornerRadius = 20;
        _completeView.backgroundColor = UIColor.whiteColor;
    }
    return _completeView;
}
- (UIView *)aligment {
    if (!_aligment) {
        _aligment = [UIView new];
    }
    return _aligment;
}
- (UIImageView *)completeIcon {
    if (!_completeIcon) {
        _completeIcon = [UIImageView new];
        _completeIcon.contentMode = UIViewContentModeScaleAspectFit;
        _completeIcon.image = [UIImage imageNamed:@"icon_check_complete"];
    }
    return _completeIcon;
}
- (UILabel *)completeTitleLabel {
    if (!_completeTitleLabel) {
        _completeTitleLabel = [UILabel new];
        _completeTitleLabel.text = @"Certification Completed";
        _completeTitleLabel.textColor = UIColorHex(#1B1B1B);
    }
    return _completeTitleLabel;
}
- (UIView *)mymaskView {
    if (!_mymaskView) {
        _mymaskView = [UIView new];
        _mymaskView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.3];
    }
    return _mymaskView;
}
@end


@interface SLSocialSecurityCardTableViewCell ()
@property (nonatomic, strong) UIView *content;
@end

@implementation SLSocialSecurityCardTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = UIColor.clearColor;
        self.contentView.backgroundColor = UIColorHex(#F5F5F5);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.content];
        [self.contentView addSubview:self.selectView];
        [self.contentView addSubview:self.selectTitleLabel];
        [self.contentView addSubview:self.selectButton];
        
        [self.contentView addSubview:self.cardView];
        [self.contentView addSubview:self.idCardView];
        [self.contentView addSubview:self.faceCardView];
        
        [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
        
        [self.selectView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.content).offset(19);
            make.top.equalTo(self.content).offset(14);
            make.height.mas_equalTo(45);
            make.width.mas_equalTo(225);
        }];
        [self.selectTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.selectView).offset(28);
            make.centerY.equalTo(self.selectView);
        }];
        [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.selectView).inset(0);
            make.centerY.equalTo(self.selectView);
            make.width.height.mas_equalTo(45);
        }];
        [self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.content);
            make.top.equalTo(self.selectView.mas_bottom).offset(13);
            make.bottom.equalTo(self.content);
        }];
        [self.idCardView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.cardView).inset(20);
            make.top.equalTo(self.cardView);
            make.height.mas_equalTo(343-54);
        }];
        [self.faceCardView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.cardView).inset(20);
            make.top.equalTo(self.idCardView.mas_bottom);
            make.height.mas_equalTo(343-54);
            make.bottom.equalTo(self.cardView);
        }];
        
    }
    return self;
}

- (UIView *)content {
    if (!_content) {
        _content = [UIView new];
        _content.backgroundColor = UIColor.whiteColor;
        _content.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _content.layer.borderWidth = 1.5;
        _content.layer.cornerRadius = 20;
    }
    return _content;
}
- (UIView *)selectView {
    if (!_selectView) {
        _selectView = [UIView new];
        _selectView.backgroundColor = UIColorHex(#FDC5E0);
        _selectView.layer.cornerRadius = 20;
        _selectView.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _selectView.layer.borderWidth = 1.5;
    }
    return _selectView;
}
- (UILabel *)selectTitleLabel {
    if (!_selectTitleLabel) {
        _selectTitleLabel = [UILabel new];
        _selectTitleLabel.font = aspectDefaultFont(14);
        _selectTitleLabel.textColor = UIColorHex(#1B1B1B);
        _selectTitleLabel.text = @"Social Security Card";
    }
    return _selectTitleLabel;
}
- (UIButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectButton.backgroundColor = UIColorHex(#1B1B1B);
        _selectButton.layer.cornerRadius = 11;
        [_selectButton setImage:[UIImage imageNamed:@"icon_auth_refresh"] forState:UIControlStateNormal];
    }
    return _selectButton;
}

-(UIView *)cardView {
    if (!_cardView) {
        _cardView = [UIView new];
        _cardView.backgroundColor = UIColorHex(#1B1B1B);
    }
    return _cardView;
}
- (SLSocialSecurityCard *)idCardView {
    if (!_idCardView) {
        _idCardView = [SLSocialSecurityCard new];
        _idCardView.titleView.titleLabel.text = @"Id Card Portrait Face Photo";
        _idCardView.layer.cornerRadius = 20;
        _idCardView.isComplete = NO;
    }
    return _idCardView;
}
- (SLSocialSecurityCard *)faceCardView {
    if (!_faceCardView) {
        _faceCardView = [SLSocialSecurityCard new];
        _faceCardView.titleView.titleLabel.text = @"Face Recognition";
        _faceCardView.layer.cornerRadius = 20;
        _faceCardView.isComplete = NO;
    }
    return _faceCardView;
}
@end
